const mongoose = require('mongoose');

const { Schema, model } = mongoose;

const userSchema = new Schema({
    __v:{  type: String, select:false },
    name: { type: String, required: true},
    password: { type: String, required: true, select:false},
    avatar_url:{ type: String },//图片途径
    gender: { type: String, enum: ['male', 'female'], default: 'male', required:true},//性别
    headline: { type: String },//个性签名
    locations: { type: [{ type:Schema.Types.ObjectId, ref: 'Topic'  }], select:false},//详细地址
    business: { type:Schema.Types.ObjectId, ref: 'Topic', select:false },//行业
    employments: {//职业经历
        type:[{
            company:{ type:Schema.Types.ObjectId, ref: 'Topic' },
            job: { type:Schema.Types.ObjectId, ref: 'Topic' }
        }],
        select:false
    },    
    educations: {//教育经历
        type:[{
            school:{ type:Schema.Types.ObjectId, ref: 'Topic' },
            major: { type:Schema.Types.ObjectId, ref: 'Topic' },
            diploma: { type:Number, enum:[1, 2, 3, 4, 5] },
            entrance_year: { type:Number },
            graduation_year: { type:Number }
        }],
        select:false
    },
    following:{//话题列表
        type:[{ type: Schema.Types.ObjectId, ref: 'User' }],
        select:false,
    },
    
    followingTopics:{//问题列表
        type:[{ type: Schema.Types.ObjectId, ref: 'Topic' }],
        select:false,
    },
    likingAnswers: {//赞过得答案
        type: [{ type: Schema.Types.ObjectId, ref: 'Answer' }],
        select: false,
    },
    dislikingAnswers: {//踩过得答案
        type: [{ type: Schema.Types.ObjectId, ref: 'Answer' }],
        select: false,
    },
    collectingAnswers: {//收藏答案
        type: [{ type: Schema.Types.ObjectId, ref: 'Answer' }],
        select: false,
    },
})

module.exports = model('User', userSchema, 'users');